//
//  TabBarButton.swift
//  FleaMarket
//
//  Created by 李帅 on 16/10/25.
//  Copyright © 2016年 lishuai. All rights reserved.
//

import UIKit

class TabBarButton: UIButton {

    var image_size: CGSize {
//        return (self.imageView?.image?.size)!
        return (UIImage(named: "account_highlight")?.size)!
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.imageView?.contentMode = UIViewContentMode.center
        self.titleLabel?.textAlignment = .center
        self.titleLabel?.font = UIFont.systemFont(ofSize: 8.0)
        self.adjustsImageWhenHighlighted = false
        self.setTitleColor(UIColor(hexString: "#333333"), for: .normal)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func titleRect(forContentRect contentRect: CGRect) -> CGRect {
        
        let title_x: CGFloat = 0
        let title_y: CGFloat = self.image_size.height + 10
        let title_width: CGFloat = self.width
        let title_height: CGFloat = 10
        return CGRect(x: title_x, y: title_y, width: title_width, height: title_height)
        
    }
    
    override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
        
        let image_x: CGFloat = 0
        let image_y: CGFloat = 7.5
        let image_width: CGFloat = self.width
        let image_height: CGFloat = self.image_size.height
        return CGRect(x: image_x, y: image_y, width: image_width, height: image_height)
        
    }
}
